﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MvcEngine.Core.Account;
using System.Web;
using MvcEngine.Core.Helpers;
using System.Linq.Expressions;
using System.Web.Mvc;

namespace MvcEngine.Core.Extensions
{
    public static class UserExtensions
    {
        public static bool IsAuthenticated(this User user)
        {
            if (HttpContext.Current.User == null)
                return false;
            return HttpContext.Current.User.Identity.IsAuthenticated;
        }

        public static bool IsAdmin(this User user) 
        {
            return IsInRole(user, Constants.Roles.Administrators);
        }

        public static bool IsInRole(this User user, string roleName)
        {
            var userRoles = AccountManager.Current.GetRolesForUser(user);
            return userRoles.Any(r => r.Name == roleName);
        }

        public static MarkupMode MarkupMode(this User user)
        {
            return SessionHelper.Markup;
        }
    }
}
